package com.example.home.active_function;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class ActivityAdapter extends RecyclerView.Adapter<ActivityAdapter.MyHoldy> {
    private Context context;
    private List<ActivityBean.RowsBean> list;
    private View view;

    public ActivityAdapter(Context context, List<ActivityBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_list, null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        Glide.with(context).load(ip + list.get(position).getImgUrl()).into(holder.cover);
        holder.name.setText(list.get(position).getName());
        String content = list.get(position).getContent();
        holder.content.setText(Html.fromHtml(content));
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : 3;
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        ImageView cover;
        TextView name;
        TextView content;
        RelativeLayout rootView;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            cover = itemView.findViewById(R.id.cover);
            name = itemView.findViewById(R.id.name);
            content = itemView.findViewById(R.id.content);
            rootView = itemView.findViewById(R.id.rootView);
        }
    }
}
